package com.dykj.fireFighting.server.base.dev.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.base.dev.entity.DevHisWaterZc;
import com.dykj.fireFighting.api.base.dev.entity.dto.DevHisWaterZcDto;
import com.dykj.fireFighting.api.base.dev.service.IDevHisWaterZcService;
import com.dykj.fireFighting.api.base.dev.vo.DevHisWaterZcVo;
import com.dykj.fireFighting.api.base.dev.vo.RateVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.utils.DateUtil;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.base.dev.mapper.DevHisWaterZcMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * VIEW
 *
 * @Author zly
 * @Date  2021-08-16 13:12:25
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class DevHisWaterZcServiceImpl extends BaseServiceImpl<DevHisWaterZcMapper, DevHisWaterZc> implements IDevHisWaterZcService {


    @Override
    public PageVo<DevHisWaterZcVo> queryList(DevHisWaterZcDto devHisWaterZcDto) {
        Map<String, Object> params = new HashMap<>();
        params.put("unitId",devHisWaterZcDto.getUnitId());
        params.put("status",devHisWaterZcDto.getStatus());
        params.put("devName",devHisWaterZcDto.getDevName());
        String tableIndex=null;
        if(null !=devHisWaterZcDto.getSj() && StringUtils.isNotBlank(devHisWaterZcDto.getSj())){
            String[] strings = devHisWaterZcDto.getSj().split(",");
            String beginDate=strings[0];
            tableIndex=DateUtil.getWeek(beginDate);
        }else{
            tableIndex = DateUtil.getYearWeek();
        }
        params.put("water","dev_his_water_"+tableIndex);
        params.put("zc","dev_his_zc_"+tableIndex);
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(devHisWaterZcDto.getPage());
        // 设置页大小
        page.setSize(devHisWaterZcDto.getLimit());

        return new PageVo<DevHisWaterZcVo>(this.baseMapper.queryList(page,params));
    }

    @Override
    public int getAlreadyReviewCount(HashMap<String, Object> params) {
        return this.baseMapper.getAlreadyReviewCount(params);
    }

    @Override
    public int getEffectCount(HashMap<String, Object> params) {
        return this.baseMapper.getEffectCount(params);
    }

    @Override
    public DevHisWaterZc queryByIdAndTable(String id, String tableType,String tableName) {

        return this.baseMapper.selectByIdTable(id,tableType,tableName);
    }

    @Override
    public List<RateVo> getMonthRate(HashMap<String, Object> params) {
        return this.baseMapper.getMonthRate(params);
    }

    @Override
    public List<RateVo> getRate(HashMap<String, Object> params) {
        return this.baseMapper.getRate(params);
    }
}
